"""Implementation of a binary tree with n-nodes."""

#_______________________________________________________________________________

import logging
import sys

import networkx as nx

from .._debug import logged

#_______________________________________________________________________________

_logger = logging.getLogger('nxchaos.graph.cycle')

#_______________________________________________________________________________




def build(n):
    """Returns full binary tree with requested number of nodes.
    The root is the first vertex.
    Of course networx has the tree implemented,
    but this is an example of using custom graphs in nxchaos.
    Actualy we're going to build a some sort of a heap."""

    g = nx.graph.Graph()
    g.add_nodes_from(range(1,n))


    for i in range(2, n):
        g.add_edge(i, (i/2))

    _logger.debug("{n}-node binary tree constructed.".format(n=n))

    return g
